package claim.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TextIO {

	private static final Log LOG = LogFactory.getLog(Class.class.getName());

	public TextIO() {
	}

	public void writeString(String string, URL url) {
		OutputStream output;
		try {
			// TODO hack to solve encoding of space in file string
			output = new FileOutputStream(url.getFile().replace("%20", " "));
			IOUtils.write(string, output);
			LOG.info("written output to " + url);
		} catch (FileNotFoundException e) {
			LOG.error("could not find file " + e, e);
		} catch (IOException e) {
			LOG.error("input/output error: " + e, e);
		}
	}

}
